import React from 'react'
// ===================================================================== 
const { $fn, $Lazy} = window
// ===================================================================== 
const SearchForm 	= $Lazy.state(()=>import('#cpt/form/search-form'))
const $time 		= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== 
const Index = function(option){
	const opt = {
		...option
	}
	const { value, search = true, onLoad, onRef, onForm, timeStr, onReset, resetField } = opt
	const { pagingLoading, forms } = this.state
	return (
		<SearchForm
			data	 	= { forms }
			search		= { search }
			onChange	= { ({ model }) => { this.model = {...this.model, ...model} } }
			onSubmit	= { $fn.onSubmit.bind(this) }
			onReset		= { ()=> {
				$fn.onReset.call(this, forms)
				if(resetField){
					const { forms } = this.state
					$fn.getRow(forms, resetField).idStr = 'value'
					$fn.setRow( forms, resetField, this.resetData )
					this.setState({forms})
				}
				onReset?.()
			} }
			loading		= { pagingLoading }
			{...option }
			onRef 	= { onForm ? null : ref => {this.searchFormRef = ref; onRef?.(ref)} }
			onForm	= { onForm ? ref => {
				this.searchFormRef = ref
				if(value){ ref.setValue(value) } 
				onForm?.(ref)
			} : ref => {
				// 设置默认时间
				if(timeStr){ $time.then( f => ref.setValue({ 'jz-time': f.duration[timeStr]() }) ) }
				onLoad?.(ref)
				this.searchFormRef=ref
				this?.onSearchForm?.(ref)
			}}
		/>
	)
}
export default Index